---
title: "Datos de la Facultad de Ciencias Geológicas-Físicas"
autor: "Miguel Ángel Sanz Santos"
output:
flexdashboard::flex_dashboard:
source_code: embed
logo: logos/woman.png
favicon: logos/ucm_favicon.png
social: [ "twitter", "facebook", "menu" ]
navbar:
- { title: "Datasets", href: "https://www.ucm.es/la-universidad-en-cifras", align: left }
---
```{r setup, include=FALSE}
# Cargamos las librerías necesarias para los códogps a ejecutar en el panel
library(readr)
library(readxl)
library(ggplot2)
library(plotly)
library(dplyr)
library(hrbrthemes)
library(flexdashboard)
library(rmarkdown)
library(DT)
# Hacemos la lectura de datos del fichero
datosUCM<- read_delim("datos_tratados.csv", delim = ";", escape_double = FALSE,
trim_ws = TRUE)
# Hacemos la factorización de las columnas de centros y centros
datosUCM$CURSO <- factor(datosUCM$CURSO)
datosUCM$CENTRO <- factor(datosUCM$CENTRO)
datosUCM_1 <- filter(datosUCM, CENTRO=="GEOLOGICAS" | CENTRO=="FISICAS")
datosUCM_1$CURSO <- factor(datosUCM_1$CURSO)
datosUCM_1$CENTRO <- factor(datosUCM_1$CENTRO)
```
# Página 1 {data-icon=fa-database}
## Columna 1 {data-width=650}
### Tabla de datos totales
```{r}
# Creamos una tabla interactiva
tabla_interactiva <- datatable(datosUCM_1, options = list( pageLength = 25))
tabla_interactiva
```
## Columna 2
### Gráfico totales anuales
```{r fig.width=10, fig.height=7}
ggplot(datosUCM_1) +
geom_col(aes(x = CURSO, y = TOTAL, fill = CENTRO), position = "dodge",width=0.6) +
labs(subtitle = "Gráfico con fill = CENTRO y position = dodge",
x = "Curso",
y = "Total de alumno/as."
) +
theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust = 0.5, size = 8),
# arriba(top), izquierda (left), derecha (right), abajo (bottom)
legend.position = "right"
)
```
### Gráfico totales por género
```{r fig.width=10, fig.height=7}
g1 <- ggplot(datosUCM_1) +
geom_point(aes(x = CURSO, y = TOTAL_HOMBRES),col = "#55dd55") +
geom_point(aes(x = CURSO, y = TOTAL_MUJERES),col = "#ff55ff") +
facet_grid(CENTRO ~ . ) +
labs(title = "Comparativa por género",
subtitle = "U.C.M.",
x = "\n \n Color verde son hombres y color fusia son mujeres.",
y = "Total de alumno/as \n"
) +
theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust = 1, size = 8))
g2 <- ggplotly(g1)
g2
```
# Página 2 {data-icon=fa-database data-orientation=rows}
## Fila 1
### Comparación tipo alumnos
```{r fig.width=7, fig.height=10}
datosUCM_2_M <- select(datosUCM_1,CURSO,CENTRO,TOTAL_MUJERES,PORC_MUJERES)
datosUCM_2_H <- select(datosUCM_1,CURSO,CENTRO,TOTAL_HOMBRES,PORC_HOMBRES)
# Unifico los nombres de las columnas TOTAL_MUJERES y TOTAL_MUJERES a TOTAL
# Unifico los nombres de las columnas PORC_MUJERES y PORCL_MUJERES a PORC
# Ojo que empieza en el índice 0
colnames(datosUCM_2_M)[3] <-"TOTAL"
colnames(datosUCM_2_H)[3] <-"TOTAL"
colnames(datosUCM_2_M)[4] <-"PORCENTAJE"
colnames(datosUCM_2_H)[4] <-"PORCENTAJE"
# Añado la filas de H y M
datosUCM_2_M$SEXO <- rep('Mujer', times = nrow(datosUCM_2_M))
datosUCM_2_H$SEXO <- rep('Hombre', times = nrow(datosUCM_2_H))
# Ahora uno las tablas de Hombre y Mujer
datosUCM_5 <- bind_rows(datosUCM_2_M,datosUCM_2_H)
g3<-ggplot(datosUCM_5) +
geom_boxplot(aes(y=TOTAL, x = CENTRO, fill = SEXO) ) +
labs(title = "Distribución de las mujeres y hombres que estudian en la UCM",
subtitle = "Gráficos de cajas, (geom_boxplot).",
x = " ",
y = "Número de estudiantes \n ",
caption = "Fuente: El Centro de Inteligencia Institucional, UCM."
) +
theme(axis.text.x = element_text(size = 10),
#arriba(top), izquierda (left), derecha (right)
legend.position = "top",
)
g4 <- ggplotly(g3)
g4
```
## Fila 2
### Comparación tipo alumnos
```{r fig.width=7, fig.height=10}
g5<-ggplot(datosUCM_1, aes(x=CENTRO, y=TOTAL)) +
geom_jitter(aes(color = CENTRO),width = 0.2) +
labs(title = "Distribución de los alumnos que estudian en la UCM",
subtitle = "Gráficos de cajas, (geom_boxplot)",
x = " ",
y = "Número de matriculas por año \n"
)
g6 <- ggplotly(g5)
g6
```